package com.toolmanrln.common.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @author ToolMan.RLN
 * @since 2020-05-15 17:20
 */
@Data
@ApiModel(value = "分页结果集", description = "分页结果集")
public class PageResult<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "当前页码", name = "currentPage", dataType = "Integer")
    private Integer currentPage = 1;
    @ApiModelProperty(value = "每页显示多少条", name = "pageSize", dataType = "Integer")
    private Integer pageSize = 20;
    @ApiModelProperty(value = "总页数", name = "totalPage", dataType = "Integer")
    private Integer totalPage = 0;
    @ApiModelProperty(value = "总记录数", name = "totalRows", dataType = "Long")
    private Long totalRows = 0L;
    @ApiModelProperty(value = "结果集", name = "rows", dataType = "List<T>")
    private List<T> rows;

    public PageResult(IPage<T> page) {
        this.setRows(page.getRecords());
        this.setTotalRows(page.getTotal());
        this.setCurrentPage((int) page.getCurrent());
        this.setPageSize((int) page.getSize());
        this.setTotalPage((int) page.getPages());
    }

    public PageResult() {
    }
}
